# -*- coding: utf-8 -*-
require 'gtk2'
require './Controler/NewParking.rb'
require './Controler/LoadParking.rb'

class MainPage < Gtk::Builder

  def initialize(xml)
    super()
    self << xml
    self['window1'].signal_connect("destroy") { onDestroy }
    self['window1'].show_all
      
    self.connect_signals{ |handler| method(handler) }
  end
  
  def on_create_click
    NewParking.new("View/newpark.glade") 
  end
  
  def delete
      
  end
  
  def on_load_parking
    dialog = Gtk::FileChooserDialog.new("Open File",
                                         self,
                                         Gtk::FileChooser::ACTION_OPEN,
                                         nil,
                                         [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
                                         [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT])
    
    
    if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT then
      str=dialog.filename.split('\\')
      titre=str[(str.length)-1].split('.')
      if(titre[1]=='db') then
        LoadParking.new("View/parking.glade",titre[0])
      else
        dialog = Gtk::Dialog.new("Information", self, Gtk::Dialog::DESTROY_WITH_PARENT,[ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_NONE ])
        dialog.signal_connect('response') { dialog.destroy }
        dialog.vbox.add(Gtk::Label.new(" Le nom et le prenom ne peuvent pas être vide ! ")) 
        dialog.show_all
      end
        
    end
    dialog.destroy
  end
  
  def onDestroy
    Gtk::main_quit
  end

end

  Gtk.init
  builder = MainPage.new("View/dreampark.glade")
  Gtk.main